package com.test.controller.page;

import com.test.entity.AuthUser;
import com.test.service.AuthService;
import com.test.service.BookService;
import com.test.service.GlobalService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RequestMapping("/page/admin")
@Controller
public class AdminPageController {
    @Resource
    AuthService authService;
    @Resource
    BookService bookService;
    @Resource
    GlobalService globalService;
    @RequestMapping("/index")
    public String index(HttpSession session, Model model){
        model.addAttribute("user",authService.findUser(session));
        model.addAttribute("borrowList",bookService.getAllBorrowOnAdmin());
        model.addAttribute("userCount",globalService.getUserCount());
        model.addAttribute("bookCount",globalService.getBookCount());
        model.addAttribute("borrowCount",globalService.getBorrowCount());
        System.out.println(authService.findUser(session));
        return "admin/index";
    }
    @RequestMapping("/book")
    public String book(HttpSession session,Model model){
        model.addAttribute("user",authService.findUser(session));
        model.addAttribute("bookList",bookService.allBook());
        System.out.println(authService.findUser(session));
        return "admin/book";
    }
    @RequestMapping("/add-book")
    public String add_book(HttpSession session,Model model){
        model.addAttribute("user",authService.findUser(session));
        return "admin/add-book";
    }

}
